home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Macintosh Tracker Source / Tracker Client Folder / Core 18⁄March⁄1994 / Object Access Code / ClassMessageInd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-07  |  2.1 KB  |  146 lines  |  [TEXT/KAHL]

  1. #define INDIRECT
  2.  
  3. /*
  4.  *  msg.c - message dispatcher
  5.  *
  6.  *  Copyright (c) 1991 Symantec Corporation.  All rights reserved.
  7.  *
  8.  */
  9.  
  10. #define OOPS_PRIVATE
  11. #include "oops.h"
  12.  
  13. #ifdef INDIRECT
  14.     #define __msg __msg_indirect
  15. #else
  16.     #define __msg __msg_direct
  17. #endif
  18.  
  19. extern void __msg(...);
  20.  
  21.  
  22.  
  23. #ifdef MEMDEBUG
  24. /* some extra debugging code */
  25.  
  26. #include "Memory.h"
  27.  
  28. static void MyTestFunc(void);
  29.  
  30. static void* messagetestfuncptr = MyTestFunc;
  31.  
  32. static void MyTestFunc(void)
  33.     {
  34.         void*            Temp;
  35.  
  36.         asm
  37.             {
  38.                 move.l        d0,Temp
  39.             }
  40.         CheckHandleExistence((Handle)Temp);
  41.     }
  42. #endif
  43.  
  44. /*
  45.  *  __msg - message dispatcher
  46.  *
  47.  *  The compiler, for
  48.  *
  49.  *        obj->method(args)
  50.  *
  51.  *  generates:
  52.  *
  53.  *            <<push args>>
  54.  *            MOVE.L    obj,-(SP)
  55.  *            JSR        selector
  56.  *            ...
  57.  *
  58.  *      selector:
  59.  *            JSR        __msg
  60.  *            JMP        (A0)
  61.  *
  62.  *  The dispatcher identifies which message was sent by examining the
  63.  *  "JSR selector" instruction.  It determines which method should be
  64.  *  invoked by searching the dispatch table of the object's actual
  65.  *  class, and, as necessary, its superclasses.
  66.  *
  67.  *  The address of the method to be called is returned in A0.
  68.  *
  69.  */
  70.  
  71. void
  72. __msg()
  73. {
  74.     asm {
  75.  
  76. ;;
  77. ;
  78. ;  set D1 = selector Ref, A1 ==> object
  79. ;
  80. ;;
  81.  
  82.         movea.l    4(sp),a1
  83.         move._    -(a1),d1
  84.         movea.l    8(sp),a1
  85. #ifdef MEMDEBUG
  86.         movem.l    d0/a0,-(sp)
  87.         move.l    a1,d0  ;copy object over to be inspected
  88.         move.l    messagetestfuncptr,a0
  89.         jsr        (a0)
  90.         movem.l    (sp)+,d0/a0
  91. #endif
  92.     #ifdef DEBUG
  93.         move.l    a1,d0
  94.         beq.s    @1
  95.         lsr.b    #1,d0
  96.         bcc.s    @2
  97. @1        jmp        __noObject            ;  object is 0 or odd
  98.     #endif
  99. @2
  100.     #ifdef INDIRECT
  101.         movea.l    (a1),a1
  102.     #endif INDIRECT
  103.  
  104. ;;
  105. ;
  106. ;  set A1 ==> dispatch table
  107. ;
  108. ;;
  109.  
  110. @3        movea._    (a1),a1
  111.     #ifdef DEBUG
  112.         move.l    a1,d0
  113.         bne.s    @4
  114.         jmp        __noMethod            ;  method not found
  115.     #endif
  116. @4
  117.     #ifdef BASE_REG
  118.         adda.l    BASE_REG,a1
  119.     #endif
  120.  
  121. ;;
  122. ;
  123. ;  search dispatch table
  124. ;
  125. ;;
  126.  
  127.         move.w    (a1)+,d0            ;  D0.W = #methods - 1
  128.         bmi.s    @3                    ;  (no methods defined)
  129. @5        movea._    (a1)+,a0            ;  A0 = method Ref
  130.         cmp._    (a1)+,d1            ;  match selector Ref
  131.         dbeq    d0,@5
  132.         bne.s    @3                    ;  not found - search superclass
  133.  
  134. ;;
  135. ;
  136. ;  done
  137. ;
  138. ;;
  139.  
  140.     #ifdef BASE_REG
  141.         adda.l    BASE_REG,a0
  142.     #endif
  143.  
  144.     }
  145. }
  146.